require("../util.js");
require("../component/components.js");
require("../../jsMt/util.js");
var vm = new Vue({
    el:"#chooseCity",
    data:{
        tabNum:1,
        pageNumber:"1",
        cityAdvId:"",
        cityAdvInfo:{},
        version:"1",
        parentId:"0",
        chinaList:{
            provinces:[],//省
            cities:[],//市
            areas:[]//县
        },//中国省市列表
        provinceId:"",
        cityId:"",
        citiesList:[],//市列表
        areasList:[], //区列表
        countryStateList:{},//州
        countryId:"",
        countryList:{},
        countryCityId:"",
        countryCityIdList:{}
    },
    mounted:function(){
        this.getChinaList();
        this.getCountryStateList(1);
    },
    methods:{
        //后退
        getBack:function(){
            history.go(-1);
        },
        bgimg:function(url){
            url = url?url:"";
            return {
                "background-image":'url("'+url+'"),url("")'
            }
        },
        /*获取查询字符对象*/
        getQueryStringArgs: function () {
            //取得查询字符串并去掉开头的问号
            var qs = (location.search.length > 0 ? location.search.substring(1) : ""),
                args = {},
                items = qs.length ? qs.split("&") : [],
                item = null,
                name = null,
                value = null,
                len = items.length;
            for (var i = 0; i < len; i++) {
                item = items[i].split("=");
                name = item[0];
                value = item[1];
                if (name.length) {
                    args[name] = value;
                }
            }
            return args;
        },
        //获取中国省市区列表
        getChinaList:function(){
            var that=this;
            this.ajax({url:"/selfMedia/getChinaList",data:{version:that.version},dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    that.chinaList=b.json.data;
                    console.log(that.chinaList)
                }else{
                    vm.$refs.prompt.toast("获取省市列表失败！")
                }
            });
        },
        //获取市
        getCity:function(code){
            console.log(code);
            var that=this;
            that.citiesList=[];
            that.areasList=[];
            that.provinceId=code;
            that.chinaList.cities.forEach(function(item,index){
                if(item.provinceId==code){
                    that.citiesList.push(item);
                }
            });
            console.log(that.citiesList);
        },
        // //获取区
        // getAreas:function(code){
        //     console.log(code);
        //     var that=this;
        //     that.areasList=[];
        //     that.cityId=code;
        //     that.chinaList.areas.forEach(function(item,index){
        //         // console.log(item.code)
        //         if(item.cityId==code){
        //             console.log(item.name);
        //             that.areasList.push(item);
        //         }
        //     });
        //     console.log(that.areasList);
        // }
        //获取国际
        getCountryStateList:function(type,parentId){
            var that=this;
            if(parentId){that.parentId=parentId;}
            this.ajax({url:"/selfMedia/getCountryStateList",data:{parentId:that.parentId},dataType:"json",method:"post"},function(b){
                if(b.json.code==0&&b.json.data){
                    if(type==1){
                        that.countryList={};
                        that.countryCityIdList={};
                        that.countryStateList=b.json.data;
                    }else if(type==2){
                        that.countryCityIdList={};
                        that.countryList=b.json.data;
                    }else if(type==3){
                        that.countryCityIdList=b.json.data;
                    }
                    console.log(b.json.data)
                }else{
                    vm.$refs.prompt.toast("获国际列表失败！")
                }
            });
        },
        getCountry:function(code){
            this.countryId=code;
            console.log(this.countryId)
            this.getCountryStateList(2,code)
        },
        getCountryCity:function(code){
            this.countryCityId=code;
            console.log(this.countryCityId)
            this.getCountryStateList(3,code)
        },
        getTab:function(num){
            this.tabNum=num;
        },
        //跳转
        getNext:function(item){
            console.log(item)
            location.href="/see/cityAdInfo?cityId="+item.code+"&cityName="+encodeURI(item.name);
        },
        getSear:function(){
            location.href="/cityAd/citySearch";
        }
    }
});